home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / HappyENV / Source / Null.asm < prev    next >
Assembly Source File  |  1998-03-13  |  5KB  |  268 lines

  1. *************************
  2. *     NULL-Handler    *
  3. *    12.11.95    *
  4. * (C) Martin Gierich    *
  5. *************************
  6.  
  7. * This is a Handler to provide a DOS device which does nothing like NIL:.
  8. * Mountlist entry looks like:
  9. *
  10. * NULL:
  11. *     Handler = L:NULL-Handler
  12. *     Stacksize = 2000
  13. *     Priority = 5
  14. *     GlobVec = -1
  15. * #
  16.  
  17.  
  18. DEBUG    = 1
  19.  
  20.     INCDIR    source:stripinc/
  21.     INCLUDE    exec/exec_lib.i
  22.     INCLUDE    dos/dos_lib.i
  23.     INCLUDE    dos/dosextens.i
  24.     INCLUDE    dos/filehandler.i
  25.  
  26. CALL    MACRO
  27.     jsr    _LVO\1(a6)
  28.     ENDM
  29.  
  30.     IFD    DEBUG
  31. DBUG1    MACRO
  32.     movem.l    d0-d7/a0-a6,-(sp)
  33.     move.l    \2,-(sp)
  34.     lea.l    \1(pc),a0
  35.     lea.l    (sp),a1
  36.     lea    RawHook(pc),a2
  37.     move.l    4.w,a6
  38.     jsr    _LVORawDoFmt(a6)
  39.     addq.l    #4,sp
  40.     movem.l    (sp)+,d0-d7/a0-a6 
  41.     ENDM
  42.  
  43. DBUG0    MACRO
  44.     movem.l    d0-d7/a0-a6,-(sp)
  45.     lea.l    \1(pc),a0
  46.     lea    RawHook(pc),a2
  47.     move.l    4.w,a6
  48.     jsr    _LVORawDoFmt(a6)
  49.     movem.l    (sp)+,d0-d7/a0-a6 
  50.     ENDM
  51.     ENDC
  52.  
  53.     IFND    DEBUG
  54. DBUG1    MACRO
  55.     ENDM
  56. DBUG0    MACRO
  57.     ENDM
  58.     ENDC
  59.  
  60. mn_Node        = 0
  61. fh_Port        = 4
  62. DOS_TRUE    = -1
  63. DOS_FALSE    = 0
  64. _LVORawPutChar    = -516
  65.  
  66.  
  67. ;private main structure
  68.         RSRESET
  69. MyProcess    RS.L    1
  70. MyMsgPort    RS.L    1
  71. MyPacket    RS.L    1
  72. MyDeviceNode    RS.L    1
  73. MyFileHandle    RS.L    1
  74. OpenCount    RS.L    1
  75. MyStructSize    RS.W    0
  76.  
  77.  
  78. *******************************************************
  79.  
  80. ;a5=private struct
  81. ;a6=execbase
  82. start:    movem.l    d2-d7/a2-a6,-(sp)
  83.     DBUG0    txstart
  84.     move.l    4.w,a6
  85.     moveq    #MyStructSize,d0
  86.     moveq    #1,d1
  87.     CALL    AllocMem
  88.     tst.l    d0
  89.     beq    exit
  90.     move.l    d0,a5
  91.  
  92.     sub.l    a1,a1
  93.     CALL    FindTask
  94.     move.l    d0,MyProcess(a5)
  95.     move.l    d0,a0
  96.     bset    #0,pr_Flags+3(a0)
  97.     add.l    #pr_MsgPort,d0
  98.     move.l    d0,MyMsgPort(a5)
  99.     clr.l    OpenCount(a5)
  100.  
  101.     bsr    GetPacket    process startup message
  102.     move.l    MyPacket(a5),a1
  103.     move.l    dp_Arg3(a1),d0
  104.     lsl.l    #2,d0
  105.     move.l    d0,MyDeviceNode(a5)
  106.     move.l    d0,a0
  107.     move.l    MyMsgPort(a5),dn_Task(a0)
  108.     clr.l    dn_SegList(a0)
  109.     moveq    #DOS_TRUE,d0
  110.     move.l    d0,dp_Res1(a1)
  111.     bsr    ReplyPacket
  112.     DBUG0    txed
  113.  
  114. loop    bsr    GetPacket
  115.     move.l    MyPacket(a5),a0
  116.     moveq    #DOS_TRUE,d0
  117.     move.l    d0,dp_Res1(a0)
  118.     move.l    dp_Type(a0),d0
  119.     cmp.l    #ACTION_FINDINPUT,d0
  120.     bne.s    .A
  121.     bsr    OpenOldfile
  122.     bra    loopend
  123. .A    cmp.l    #ACTION_FINDOUTPUT,d0
  124.     bne.s    .C
  125.     bsr    OpenNewfile
  126.     bra    loopend
  127. .C    cmp.l    #ACTION_END,d0
  128.     bne.s    .D
  129.     bsr    CloseFile
  130.     bra    loopend
  131. .D    cmp.l    #ACTION_READ,d0
  132.     bne.s    .E
  133.     bsr    ReadFile
  134.     bra    loopend
  135. .E    cmp.l    #ACTION_WRITE,d0
  136.     bne.s    .F
  137.     bsr    WriteFile
  138.     bra    loopend
  139. .F    cmp.l    #ACTION_DIE,d0
  140.     beq    exit2
  141.     DBUG1    txerr1,d0
  142.     move.l    MyPacket(a5),a0
  143.     clr.l    dp_Res1(a0)
  144.     move.l    #ERROR_ACTION_NOT_KNOWN,dp_Res2(a0)
  145. loopend    bsr    ReplyPacket
  146.     bra    loop
  147.  
  148. exit2    DBUG0    txend
  149.     bsr    ReplyPacket
  150.     tst.l    OpenCount(a5)
  151.     beq.s    .A
  152.     bpl    loop
  153. .A    bsr    FlushPackets
  154.     move.l    MyDeviceNode(a5),a0
  155.     clr.l    dn_Task(a0)
  156.     move.l    a5,a1
  157.     moveq    #MyStructSize,d0
  158.     CALL    FreeMem
  159.     DBUG0    txed
  160. exit    movem.l    (sp)+,d2-d7/a2-a6
  161.     moveq    #0,d0
  162.     rts
  163.  
  164. *******************************************************
  165.  
  166. * Wait for a packet then get it into MyPacket
  167. GetPacket:
  168. .A    move.l    MyMsgPort(a5),a0
  169.     CALL    WaitPort
  170.     move.l    MyMsgPort(a5),a0
  171.     CALL    GetMsg
  172.     tst.l    d0
  173.     beq.s    .A
  174.     move.l    d0,a0
  175.     move.l    mn_Node+LN_NAME(a0),MyPacket(a5)
  176.     beq.s    .A
  177.     rts
  178.  
  179. * Reply packet in MyPacket
  180. ReplyPacket:
  181.     move.l    MyPacket(a5),a2
  182.     move.l    dp_Port(a2),a0        reply port
  183.     move.l    dp_Link(a2),a1        message to send
  184.     move.l    MyMsgPort(a5),dp_Port(a2)
  185.     move.l    a2,mn_Node+LN_NAME(a1)
  186.     clr.l    mn_Node+LN_SUCC(a1)
  187.     clr.l    mn_Node+LN_PRED(a1)
  188.     CALL    PutMsg
  189.     rts
  190.  
  191. FlushPackets:
  192. .A    move.l    MyMsgPort(a5),a0
  193.     CALL    GetMsg
  194.     tst.l    d0
  195.     beq.s    .C
  196.     move.l    d0,a0
  197.     move.l    mn_Node+LN_NAME(a0),MyPacket(a5)
  198.     beq.s    .A
  199.     move.l    MyPacket(a5),a0
  200.     clr.l    dp_Res1(a0)
  201.     move.l    #ERROR_ACTION_NOT_KNOWN,dp_Res2(a0)
  202.     bsr    ReplyPacket
  203.     bra.s    .A
  204. .C    rts
  205.  
  206. *******************************************************
  207.  
  208. OpenOldfile:
  209.     move.l    MyPacket(a5),a1
  210.     DBUG1    txopeno,dp_Arg3(a1)
  211.     move.l    dp_Arg1(a1),a0
  212.     add.l    a0,a0
  213.     add.l    a0,a0
  214.     clr.l    fh_Port(a0)
  215.     addq.l    #1,OpenCount(a5)
  216.     rts
  217.  
  218. OpenNewfile:
  219.     move.l    MyPacket(a5),a1
  220.     DBUG1    txopenn,dp_Arg3(a1)
  221.     move.l    dp_Arg1(a1),a0
  222.     add.l    a0,a0
  223.     add.l    a0,a0
  224.     clr.l    fh_Port(a0)
  225.     addq.l    #1,OpenCount(a5)
  226.     rts
  227.  
  228. CloseFile:
  229.     DBUG0    txclose
  230.     subq.l    #1,OpenCount(a5)
  231.     rts
  232.  
  233. ReadFile:
  234.     move.l    MyPacket(a5),a1
  235.     DBUG0    txread
  236.     moveq    #0,d0
  237.     move.l    d0,dp_Res1(a1)
  238.     subq.l    #1,OpenCount(a5)
  239.     rts
  240.  
  241. WriteFile:
  242.     move.l    MyPacket(a5),a1
  243.     DBUG1    txwrite,dp_Arg3(a1)
  244.     move.l    dp_Arg3(a1),dp_Res1(a1)
  245.     subq.l    #1,OpenCount(a5)
  246.     rts
  247.  
  248. *******************************************************
  249.  
  250.     IFD    DEBUG
  251. RawHook    move.l    a6,-(sp)
  252.     move.l    4.w,a6
  253.     jsr    _LVORawPutChar(a6)
  254.     move.l    (sp)+,a6
  255.     rts
  256.  
  257. txstart    dc.b    "Handler start",0
  258. txend    dc.b    "Handler end",0
  259. txed    dc.b    "ed",10,0
  260. txerr1    dc.b    "%ld: Action not known",10,0
  261. txopeno    dc.b    "Open old file %b",10,0
  262. txopenn    dc.b    "Open new file %b",10,0
  263. txclose    dc.b    "Close file",10,0
  264. txread    dc.b    "Read access",10,0
  265. txwrite    dc.b    "Write %ld bytes",10,0
  266.     ENDC
  267.  
  268.